package com.awesome.common.base.mvp

import android.app.Application

/**
 * Author: JFangZ
 * Email: janezhang1901@163.com
 * Date:2021/4/8 11:32
 * Description:The base of application.
 */
open class BaseApplication : Application() {
    private val actLifecycle by lazy { ActLifecycle() }

    companion object {
        var instance: BaseApplication? = null
            private set
    }

    override fun onCreate() {
        super.onCreate()
        instance = this
        registerActivityLifecycleCallbacks(actLifecycle)
    }

    /**
     * 应用前后台状态  true app从后台进入前台了 , false app从前台进入后台
     */
    open fun setOnStateListener(listener: (isState: Boolean) -> Unit) {
        actLifecycle.setOnStateListener { listener.invoke(it) }
    }
}